//
//  ShoppingBagTableViewCell.m
//  PeopleStreet
//
//  Created by 辰领科技 on 16/1/14.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "ShoppingBagTableViewCell.h"

@implementation ShoppingBagTableViewCell

- (void)awakeFromNib {
    // Initialization code
  
    
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        UIView * vLine = [[UIView alloc]initWithFrame:flexibleFrame(CGRectMake(0, 0, 320, 1), NO)];
        vLine.backgroundColor = [UIColor colorWithWhite:0.945 alpha:1.000];
        [self.contentView addSubview:vLine];
        
        UIView * dLine = [[UIView alloc]initWithFrame:flexibleFrame(CGRectMake(0, 105, 320, 5), NO)];
        dLine.backgroundColor = [UIColor colorWithWhite:0.945 alpha:1.000];
        [self.contentView addSubview:dLine];
        

        
        _moreButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _moreButton.frame = flexibleFrame(CGRectMake(130, 50, 190, 46), NO);
        [_moreButton addTarget:self action:@selector(changeHandel:) forControlEvents:UIControlEventTouchUpInside];
        UIImageView * moreImage = [[UIImageView alloc]init];
        moreImage.frame = flexibleFrame(CGRectMake(167, 20, 11, 6), NO);
        moreImage.image = [UIImage imageNamed:@"shopping9"];
        [self.contentView addSubview:_moreButton];
        [_moreButton addSubview:moreImage];
        
        for (int i = 0; i<2; i++) {
            UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
            if (i==1) {
                button.frame = flexibleFrame(CGRectMake(12, 40, 19, 19), NO);
                [button setBackgroundImage:[UIImage imageNamed:@"shopping5"] forState:UIControlStateNormal];
                [button setBackgroundImage:[UIImage imageNamed:@"shopping4"] forState:UIControlStateSelected];
                 _choseDownButton = button;
                [self.contentView addSubview:button];
            }
           
            }
        
        //图片
        _goodsImage = [[UIImageView alloc]initWithFrame:flexibleFrame(CGRectMake(40 , 10, 79, 79), NO)];
        [self.contentView addSubview:_goodsImage];
        
        _infoLabel = [[UILabel alloc]initWithFrame:flexibleFrame(CGRectMake(130, 10, 172, 20), NO)];
        _infoLabel.numberOfLines = 0;
        _infoLabel.textAlignment = NSTextAlignmentLeft;
        _infoLabel.textColor = [UIColor colorWithWhite:0.196 alpha:1.000];
        _infoLabel.font = [UIFont systemFontOfSize:12*VerticalTexeRatio()];
        [self.contentView addSubview:_infoLabel];
        
        _propertyLabel = [[UILabel alloc]initWithFrame:flexibleFrame(CGRectMake(130, 50, 172, 20), NO)];
        _propertyLabel.numberOfLines = 0;
        _propertyLabel.textAlignment = NSTextAlignmentLeft;
        _propertyLabel.textColor = [UIColor colorWithWhite:0.631 alpha:1.000];
        _propertyLabel.font = [UIFont systemFontOfSize:12*VerticalTexeRatio()];
        [self.contentView addSubview:_propertyLabel];
        
        _priceLabel = [[UILabel alloc]initWithFrame:flexibleFrame(CGRectMake(130, 75, 150, 15), NO)];
        _priceLabel.textAlignment = NSTextAlignmentLeft;
        _priceLabel.textColor = [UIColor colorWithRed:0.859 green:0.161 blue:0.161 alpha:1.000];
        _priceLabel.font = [UIFont systemFontOfSize:16*VerticalTexeRatio()];
        [self.contentView addSubview:_priceLabel];
        

        
       
        
        _numberLabel = [[UILabel alloc]initWithFrame:flexibleFrame(CGRectMake(0, 75, 300, 15), NO)];
        _numberLabel.textAlignment = NSTextAlignmentRight;
        _numberLabel.textColor = [UIColor colorWithWhite:0.231 alpha:1.000];
        _numberLabel.font = [UIFont systemFontOfSize:13*VerticalTexeRatio()];
        
        [self.contentView addSubview:_numberLabel];
        
        
        _editingView = [[UIView alloc]initWithFrame:flexibleFrame(CGRectMake(120, 1, 200, 55), NO)];
        _editingView.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:_editingView];
        
        
        _neNumberLabel =  [[UILabel alloc]initWithFrame:flexibleFrame(CGRectMake(52, 17, 103, 23), NO)];
        _neNumberLabel.textAlignment = NSTextAlignmentCenter;
        _neNumberLabel.textColor = [UIColor colorWithWhite:0.196 alpha:1.000];
        _neNumberLabel.layer.borderWidth = 1;
        _neNumberLabel.layer.borderColor = [UIColor colorWithWhite:0.859 alpha:1.000].CGColor;

        _neNumberLabel.font = [UIFont systemFontOfSize:17*VerticalTexeRatio()];
        [_editingView addSubview:_neNumberLabel];

      
        
        for (int i = 0; i<2; i++) {
            UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.frame = flexibleFrame(CGRectMake(15+152*i, 17, 24, 23), NO);
            button.layer.borderWidth = 1;
            button.layer.borderColor = [UIColor colorWithWhite:0.859 alpha:1.000].CGColor;
            UIButton * Button = [UIButton buttonWithType:UIButtonTypeCustom];
            Button.frame = flexibleFrame(CGRectMake(155*i, 0, 55, 46), NO);
            Button.backgroundColor = [UIColor clearColor];
            
            UIImageView * image = [[UIImageView alloc]init];
            if (i==0) {
                _deleteButton = Button;
                [_deleteButton addTarget:self action:@selector(deleteHandel:) forControlEvents:UIControlEventTouchUpInside];
                image.frame = flexibleFrame(CGRectMake(5, 11, 13, 1.5), NO);
                image.image = [UIImage imageNamed:@"shopping10"];
            }else{
                _addButton = Button;
                 [_addButton addTarget:self action:@selector(addHandel:) forControlEvents:UIControlEventTouchUpInside];
                image.frame = flexibleFrame(CGRectMake(5.5, 5, 13, 13), NO);
             image.image = [UIImage imageNamed:@"shopping8"];
            }
             [_editingView addSubview:button];
            [_editingView addSubview:Button];
            [button addSubview:image];
        }
        
        
        
        _choseButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _choseButton.frame = flexibleFrame(CGRectMake(0,0, 39, 70), NO);
        _choseButton.backgroundColor = [UIColor clearColor];
        [_choseButton addTarget:self action:@selector(choseHandel:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:_choseButton];
        
    }
    
    return self;
}


- (void)choseHandel:(UIButton *)sender{//勾选
    sender.selected = !sender.selected;
    _choseDownButton.selected = sender.selected;
    if (sender.selected == YES) {
         _choseBlock(@"1");
    }else{
     _choseBlock(@"0");
    }
   
}


- (void)infoHandel:(UIButton *)sender{//详情
    if (self.infoBlock) {
        self.infoBlock(@"1");
    }
}


- (void)addHandel:(UIButton *)sender{//增加件数
    if (self.addBlock) {
        self.addBlock(@"1");
    }
}

- (void)deleteHandel:(UIButton *)sender{//减少件数
    if (self.deleteBlock) {
        self.deleteBlock(@"1");
    }
}

- (void)changeHandel:(UIButton *)sender{//改变样式
    if (self.changeBlock) {
        self.changeBlock(@"1");
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
